<?php

class testUrlBean extends UnitTestCase {

    function testConstructor() {
        $sample='http://webappkit.net/base/path/sector/subsector/page.php?var=value&var2=12#hello-world';
        $url=new UrlBean($sample,'base/path');
        // $this->dump($url);
        $this->assertEqual($url->getAbsolute(),$sample);
        $this->assertEqual($url->getRelative(),'sector/subsector/page.php?var=value&var2=12#hello-world');
        $this->assertEqual($url->getScheme(),'http');
        $this->assertEqual($url->getHost(),'webappkit.net');
        $this->assertEqual($url->getBasePath(),'base/path');
        $this->assertEqual($url->getPath(),'sector/subsector/page.php');
        $this->assertEqual($url->getUriSegment(0),'sector');
        $this->assertEqual($url->getUriSegment(1),'subsector');
        $this->assertEqual($url->getUriSegment(2),'page.php');
        $this->assertEqual($url->getQuery(),'var=value&var2=12');
        $this->assertEqual($url->getFragment(),'hello-world');
    }

    function testSetters() {
        $url=new UrlBean('http://www.subdomain.domain.com');
        // $url->errors(true);
        // $url->setHost('www.subdomain.domain.com');
        // $this->dump(urlbean::parsestring('www.subdomain.domain.com'));
        $this->assertFalse($url->setScheme(null));
        $this->assertEqual($url->getAbsolute(),'http://www.subdomain.domain.com/');
        // $this->dump($url);
    }

    /**
     * testing base path and href
     */
    function testBase() {
        $url=new UrlBean('http://localhost/application/sector/page','application');
        $this->assertEqual($url->getBasePath(),'application');

        $this->assertTrue($url->setbasePath('application/sector'),true);
        $this->assertEqual($url->getBasePath(),'application/sector');
        $this->assertEqual($url->getPath(),'page');
    }
}